import 'dart:async';
import 'dart:ui';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:kzcity_picker/kzcity_picker.dart';
import 'package:magic_car/UI/webview.dart';
import 'package:magic_car/util/colors.dart';
import 'package:magic_car/util/config.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toast/toast.dart';
import 'package:flutter/material.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
// import 'package:amap_location/amap_location.dart';
import 'package:permission_handler/permission_handler.dart';

//import 'package:city_pickers/city_pickers.dart';
class RegistPage extends StatefulWidget {
  RegistPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<RegistPage> {
  TextEditingController _nametroller = new TextEditingController();
  TextEditingController _agetroller = new TextEditingController();
  TextEditingController _mobiletroller = new TextEditingController();
  TextEditingController _validtroller = new TextEditingController();
  TextEditingController _idcardtroller = new TextEditingController();
  TextEditingController _expricetroller = new TextEditingController();
  TextEditingController _passtroller = new TextEditingController();
  TextEditingController _confirmpasstroller = new TextEditingController();
  List formList;
  bool agreen = false;
  File _image;
  String card_z = '';
  String card_f = '';
  bool select_img = false;
  Timer _timer;
  int _seconds = 60;
  String lng = "";
  String lat = "";
  String _verifyStr = '获取验证码';

  String areaStr = '省份/县市/区域';

  String provinceId = '';
  String provinceName = '';
  String cityName = '';
  String cityId = '';
  String areaName = '';
  String areaId = '';
  List provincedatalist = [];

  initState() {
    super.initState();
    formList = [
      {
        "title": '客户姓名',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
      {
        "title": '车牌号',
        'sub_title': '云A00001云A00001云A00',
        'sub_color': Color.fromRGBO(27, 182, 251, 1)
      },
    ];
    getareadata();
    //  startLocations();//获取位置
  }

  /// 启动倒计时的计时器。
  void _startTimer() {
    print('开始计时');
    // 计时器（`Timer`）组件的定期（`periodic`）构造函数，创建一个新的重复计时器。
    _timer = Timer.periodic(Duration(seconds: 1), (timer) {
      print(_seconds.toString());
      if (_seconds == 0) {
        _cancelTimer();

        setState(() {
          _verifyStr = '重新发送';
          _seconds = 60;
        });
        return;
      }

      _verifyStr = '已发送$_seconds' + 's';
      setState(() {
        _verifyStr = '已发送$_seconds' + 's';
      });
      _seconds--;
      if (_seconds == 0) {
        _verifyStr = '重新发送';
      }
    });
  }

  /// 取消倒计时的计时器。
  void _cancelTimer() {
    print('取消');
    // 计时器（`Timer`）组件的取消（`cancel`）方法，取消计时器。
    _timer?.cancel();
  }

  startLocations() async {
    if (await Permission.location.request().isGranted) {
      // 干你该干的事
    }
  }

  Widget buildcontent() {
    List<Widget> tiles = [];
    Widget content;
    var name = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '姓名',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                      controller: _nametroller,
                      decoration: InputDecoration(
                        contentPadding:
                            const EdgeInsets.symmetric(vertical: 4.0),
                        hintText: '请输入姓名',
                        hintStyle: TextStyle(fontSize: Config.hit_base_size),
                        border: OutlineInputBorder(
                          borderSide: BorderSide.none,
                        ),
                      ),
                      onChanged: (val) {
                        print(val);
                      },
                    )),
                flex: 2,
              )
            ],
          ),
        ));
    var age = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '工龄',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _agetroller,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          contentPadding:
                              const EdgeInsets.symmetric(vertical: 4.0),
                          hintText: '请输入工龄',
                          hintStyle: TextStyle(fontSize: Config.hit_base_size),
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var tel = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '电话号码',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _mobiletroller,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          contentPadding:
                              const EdgeInsets.symmetric(vertical: 4.0),
                          hintText: '请输入电话号码',
                          hintStyle: TextStyle(fontSize: Config.hit_base_size),
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var valid = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '验证码',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _validtroller,
                        decoration: InputDecoration(
                          contentPadding:
                              const EdgeInsets.symmetric(vertical: 4.0),
                          hintText: '验证码',
                          hintStyle: TextStyle(fontSize: Config.hit_base_size),
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: Align(
                      alignment: Alignment.centerRight,
                      child: new Container(
                        child: new Material(
                          //INK可以实现装饰容器
                          child: new Ink(
                            //用ink圆角矩形
                            // color: Colors.red,
                            decoration: new BoxDecoration(
                              //背景
                              color: Colors.white,
                              //设置四周圆角 角度
                              borderRadius:
                                  BorderRadius.all(Radius.circular(5.0)),
                              //设��四周边框
                              border: new Border.all(
                                  width: 1, color: Colours.app_main),
                            ),
                            child: new InkWell(
                                //圆角设置,给水波纹也设置同样的圆角
                                //如果这里不设置就会出现矩形的水波纹效果
                                borderRadius: new BorderRadius.circular(15.0),
                                //设置点击事件回调
                                onTap: () {
                                  if (_seconds == 60) {
                                    sendcode();
                                  }
                                },
                                child: Container(
                                  //设置 child 居中
                                  alignment: Alignment(0, 0),
                                  height: 35,
                                  width: 105,
                                  child: Text(_verifyStr,
                                      style:
                                          TextStyle(color: Colours.app_main)),
                                )),
                          ),
                        ),
                      )
                      // child: new RaisedButton(
                      //   child: Text('申请补考'),
                      //   onPressed: () {},
                      // ),
                      ),
                  // child: new RaisedButton(
                  //   onPressed: () {
                  //     sendcode();
                  //   },
                  //   child: Text('获取验证码'),
                  // ),
                ),
                flex: 1,
              )
            ],
          ),
        ));
    var code = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new Text(
                      '身份证号',
                      style: TextStyle(
                          fontSize: 15,
                          color: Color.fromRGBO(102, 102, 102, 1)),
                    )),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _idcardtroller,
                        decoration: InputDecoration(
                          contentPadding:
                              const EdgeInsets.symmetric(vertical: 4.0),
                          hintText: '请输入身份证号',
                          hintStyle: TextStyle(fontSize: Config.hit_base_size),
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var city = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: new GestureDetector(
            onTap: () async {
              FocusScope.of(context).requestFocus(FocusNode());
              var result;
              if (provincedatalist.length == 0) {
                result = await KzcityPicker.showPicker(
                  context,
                );
              } else
                result = await KzcityPicker.showPicker(context,
                    datas: provincedatalist);

              if (result != null) {
                setState(() {
                  provinceName = result.province;
                  provinceId = result.provinceCode.toString();
                  cityName = result.city;
                  cityId = result.cityCode.toString();
                  areaName = result.area;
                  areaId = result.areaCode.toString();
                  setState(() {
                    areaStr = provinceName + cityName + areaName;
                  });
                });
              }
              // Result result = await CityPickers.showCityPicker(
              //     context: context,
              //     cancelWidget:
              //         Text('取消', style: TextStyle(color: Colors.black54)),
              //     confirmWidget:
              //         Text("确定", style: TextStyle(color: Colors.blue)));
              // print(result);
              // if (result != null) {
              //   setState(() {
              //     provinceName=result.provinceName;
              //     provinceId=result.provinceId.toString();
              //     cityName=result.cityName;
              //     cityId=result.cityId.toString();
              //     areaName=result.areaName;
              //     areaId=result.areaId.toString();

              //     areaStr =
              //         "${result.provinceName}/${result.cityName}/${result.areaName}";
              //     // this.area =
              //     //     "${result.provinceName}/${result.cityName}/${result.areaName}";
              //   });
              // }
            },
            child: Container(
              color: Colors.white,
              height: 50,
              child: new Row(
                children: <Widget>[
                  Expanded(
                    child: new Padding(
                      padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                      child: RichText(
                        text: TextSpan(
                            text: '地区选择',
                            style: TextStyle(
                                fontSize: 15,
                                color: Color.fromRGBO(102, 102, 102, 1)),
                            children: [
                              TextSpan(
                                  text: '*',
                                  style: TextStyle(
                                      fontSize: 14, color: Colors.red))
                            ]),
                      ),
                    ),
                    flex: 1,
                  ),
                  Expanded(
                    child: new Padding(
                        padding: new EdgeInsets.fromLTRB(13, 0, 10, 0),
                        child: new GestureDetector(child: new Text(areaStr))),
                    // new Padding(
                    //     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    //     child: new GestureDetector(child: new Text('城市'))),
                    // new Padding(
                    //     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    //     child: new GestureDetector(child: new Text('区/县'))),
                    flex: 2,
                  )
                ],
              ),
            )));

    var cardimg = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '上传照片',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '（身份证正、反两面）',
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color.fromRGBO(102, 102, 102, 1)))
                        ]),
                  ),
                ),
              ),
              // Expanded(
              //   child: new Padding(
              //       padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
              //       child: new TextField(

              //           decoration: InputDecoration(
              //             hintText: '请输入身份证号',
              //         border: OutlineInputBorder(
              //          borderSide: BorderSide.none,
              //         ),
              //       ))),
              //   flex: 2,
              // )
            ],
          ),
        ));

    var cardimg1 = Padding(
        padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
        child: Container(
          color: Colors.white,
          height: 100,
          child: new Row(
            children: <Widget>[
              Expanded(
                  child: new Padding(
                    padding: new EdgeInsets.fromLTRB(0, 0, 10, 10),
                    child: new GestureDetector(
                      onTap: () {
                        getImage(1);
                      },
                      child: card_z == ""
                          ? Image.asset('resource/images/user/card_img1.png')
                          : CachedNetworkImage(imageUrl: card_z),

                      //  FadeInImage.assetNetwork(
                      //   placeholder: "resource/images/user/card_img1.png",
                      //   image: card_z,
                      // )
                    ),
                    // new Image.asset('resource/images/user/card_img1.png'),
                  ),
                  flex: 1),
              Expanded(
                  child: new Padding(
                    padding: new EdgeInsets.fromLTRB(0, 0, 10, 10),
                    child: new GestureDetector(
                      onTap: () {
                        getImage(2);
                      },
                      child: card_f == ""
                          ? Image.asset('resource/images/user/card_img2.png')
                          : CachedNetworkImage(imageUrl: card_f),
                      //  FadeInImage.assetNetwork(
                      //   placeholder: "resource/images/user/card_img2.png",
                      //   image: card_f,
                      // )
                    ),
                    // new Image.asset('resource/images/user/card_img2.png'),
                  ),
                  flex: 1),
            ],
          ),
        ));
    var experice = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '相关工作经历',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '',
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color.fromRGBO(102, 102, 102, 1)))
                        ]),
                  ),
                ),
              ),
            ],
          ),
        ));
    var expericetext = Padding(
        padding: new EdgeInsets.fromLTRB(0, 0, 0, 0),
        child: Container(
          color: Colors.white,
          height: 150,
          child: new Column(
            children: <Widget>[
              new Padding(
                padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                child: TextField(
                  maxLines: 5,
                  controller: _expricetroller,
                  decoration: InputDecoration(
                      border: InputBorder.none,
                      fillColor: Colours.base_page_color,
                      filled: true,
                      labelText: '输入工作经历'),
                ),
              ),
            ],
          ),
        ));
    var pass = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '登录密码',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        // textAlignVertical: TextAlignVertical.bottom,
                        controller: _passtroller,
                        decoration: InputDecoration(
                          contentPadding:
                              const EdgeInsets.symmetric(vertical: 4.0),
                          hintText: '请输入登录密码',
                          hintStyle: TextStyle(fontSize: Config.hit_base_size),
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var confirmpass = Padding(
        padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
        child: Container(
          color: Colors.white,
          height: 50,
          child: new Row(
            children: <Widget>[
              Expanded(
                child: new Padding(
                  padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                  child: RichText(
                    text: TextSpan(
                        text: '再次确认',
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(102, 102, 102, 1)),
                        children: [
                          TextSpan(
                              text: '*',
                              style: TextStyle(fontSize: 14, color: Colors.red))
                        ]),
                  ),
                ),
                flex: 1,
              ),
              Expanded(
                child: new Padding(
                    padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
                    child: new TextField(
                        controller: _confirmpasstroller,
                        decoration: InputDecoration(
                          contentPadding:
                              const EdgeInsets.symmetric(vertical: 4.0),
                          hintText: '请输入密码',
                          hintStyle: TextStyle(fontSize: Config.hit_base_size),
                          border: OutlineInputBorder(
                            borderSide: BorderSide.none,
                          ),
                        ))),
                flex: 2,
              )
            ],
          ),
        ));
    var agreen = Padding(
        padding: new EdgeInsets.fromLTRB(10, 10, 0, 0),
        child: Row(
          // crossAxisAlignment: CrossAxisAlignment.baseline,
          children: <Widget>[
            // Expanded(
            //   flex: 1,
            //   child:
            Container(
              alignment: new FractionalOffset(0.0, 0.0),
              width: 20,
              height: 20,
              child: Checkbox(
                activeColor: Color.fromRGBO(27, 182, 251, 1),
                checkColor: Colors.blue,
                value: this.agreen,
                onChanged: (value) {
                  setState(() {
                    this.agreen = value;
                  });
                },
              ),
            ),
            // Expanded(
            //   flex:2,
            //   child:
            Padding(
                padding: new EdgeInsets.fromLTRB(5, 0, 0, 0),
                child: Container(
                    child: GestureDetector(
                  onTap: () {
                    Navigator.of(context)
                        .push(new MaterialPageRoute(builder: (_) {
                      return new AgreementPage();
                    }));
                  },
                  child: RichText(
                    text: TextSpan(
                        text: '我已经阅读并同意',
                        style: TextStyle(
                            fontSize: 12, color: Color.fromRGBO(51, 51, 51, 1)),
                        children: [
                          TextSpan(
                              text: '【车魔估检测师入驻协议】',
                              style: TextStyle(
                                fontSize: 12,
                                color: Colours.app_main,
                              ))
                        ]),
                  ),
                )))
            //)
          ],
        ));
    var btn = Padding(
      padding: new EdgeInsets.fromLTRB(10, 20, 10, 40),
      child: new SizedBox(
          width: double.infinity,
          height: 45,
          child: new RaisedButton(
            child: Text('注册'),
            textColor: Colors.white,
            color: Colours.app_main,
            onPressed: () {
              regist();
            },
          )),
    );
    tiles.add(name);
    tiles.add(age);
    tiles.add(city);
    tiles.add(tel);
    tiles.add(valid);
    tiles.add(code);
    tiles.add(cardimg);
    tiles.add(cardimg1);
    tiles.add(experice);
    tiles.add(expericetext);
    tiles.add(pass);
    tiles.add(confirmpass);
    tiles.add(agreen);
    tiles.add(btn);
    // for (var item in formList) {
    //   tiles.add(Padding(
    //       padding: new EdgeInsets.fromLTRB(0, 1, 0, 0),
    //       child: Container(
    //           color: Colors.white,
    //           height: 50,
    //           child: new Row(
    //             children: <Widget>[
    //               Expanded(
    //                 child: new Padding(
    //                     padding: new EdgeInsets.fromLTRB(10, 0, 10, 0),
    //                     child: new Text(
    //                       item['title'],
    //                       style: TextStyle(fontSize: 15,color: Color.fromRGBO(102, 102, 102, 1)),
    //                     )),
    //                 flex: 1,
    //               ),
    //               new Padding(
    //                   padding: new EdgeInsets.fromLTRB(0, 0, 10, 0),
    //                   child: new Text(
    //                     item['sub_title'],
    //                     style:
    //                         TextStyle(fontSize: 15, color: item['sub_color']),
    //                   )),
    //             ],
    //           ))));
    // }
    content = new Column(
        children: tiles //重点在这里，因为用编辑器写Column生成的children后面会跟一个<Widget>[]，
        //此时如果我们直接把生成的tiles放在<Widget>[]中是会报一个类型不匹配的错误，把<Widget>[]删了就可以了
        );
    return content;
  }

//注册
  void regist() async {
    SharedPreferences pref = await SharedPreferences.getInstance();
    FocusScope.of(context).requestFocus(FocusNode());

    var toastmsg = "";
    if (_nametroller.text.trim().length == 0) {
      toastmsg = '请填写姓名';
    } else if (_agetroller.text.trim().length == 0) {
      toastmsg = '请填写工龄';
    } else if (_mobiletroller.text.trim().length == 0) {
      toastmsg = '请填写电话号码';
    } else if (_validtroller.text.trim().length == 0) {
      toastmsg = '请填写验证码';
    } else if (_idcardtroller.text.trim().length == 0) {
      toastmsg = '请填写身份证';
    } else if (_expricetroller.text.trim().length == 0) {
      toastmsg = '请填写工作经验';
    } else if (_passtroller.text.trim().length == 0) {
      toastmsg = '请填写登录密码';
    } else if (_confirmpasstroller.text.trim().length == 0) {
      toastmsg = '请填写密码';
    } else if (agreen == false) {
      toastmsg = '请勾选入职协议';
    } else if (card_z == "" || card_f == "") {
      toastmsg = '请上传身份证';
    }

    if (toastmsg != "") {
      Toast.show(toastmsg, context);
      return;
    }

    Map<String, String> map = new Map();
    map["mobile"] = _mobiletroller.text.trim();
    map["code"] = _validtroller.text.trim();
    map["name"] = _nametroller.text.trim();
    map["workhistory"] = _expricetroller.text.trim();
    map["lengthofservice"] = _agetroller.text.trim();
    map["idcard"] = _idcardtroller.text.trim();
    map["password"] = _passtroller.text.trim();
    map["idcardback"] = card_f;
    map["idcardfront"] = card_z;
    map["registed_Id"] = pref.getString('registeid');

    map['provinceId'] = provinceId;
    map['provinceName'] = provinceName;
    map['cityName'] = cityName;

    map['cityId'] = cityId;
    map['areaName'] = areaName;
    map['areaId'] = areaId;

    HttpHelper.post(HttpHelper.API_Reg, (data) {
      if (data != null) {
        print(data);

        if (data["code"].toString() == "1") {
          Toast.show('注册后请耐心等待审核，工作人员将在1个工作日内完成审核与您联系！', context);
          Navigator.pop(context);
        } else {
          Toast.show(data["msg"], context);
        }
      }
    }, params: map);
  }

  getareadata() {
    Map<String, String> map = new Map();
    map["mobile"] = _mobiletroller.text.trim();
    HttpHelper.post(HttpHelper.API_Area_data, (data) {
      if (data != null) {
        print(data);
        if (data["status"].toString() == "1") {
          // Navigator.pop(context);
          setState(() {
            provincedatalist = data['result']['defaultList'];
          });
        }
      }
    }, params: map);
  }

//发送验证码
  sendcode() {
    FocusScope.of(context).requestFocus(FocusNode());

    if (_mobiletroller.text.trim().length == 0) {
      Toast.show("填写手机号", context);
      return;
    }
    Map<String, String> map = new Map();
    map["mobile"] = _mobiletroller.text.trim();
    HttpHelper.post(HttpHelper.API_SendCode, (data) {
      if (data != null) {
        print(data);
        Toast.show(data["msg"], context);

        if (data["code"].toString() == "1") {
          // Navigator.pop(context);
          _startTimer();
          setState(() {
            // orderInfo=data["data"];
          });
        }
      }
    }, params: map);
  }

  //选择图片
  getimgs(type, card) async {
    if (type == 1) {
      var image = await ImagePicker.pickImage(source: ImageSource.gallery);

      setState(() {
        _image = image;
        select_img = true;
      });
    } else {
      var image = await ImagePicker.pickImage(source: ImageSource.camera);

      setState(() {
        _image = image;
        select_img = true;
      });
    }
    if (_image == null) return;
    Map<String, String> map = new Map();

    HttpHelper.upLoadImage(_image, (data) {
      if (card == 1) {
        setState(() {
          card_z = data["url"];
        });
      } else {
        setState(() {
          card_f = data["url"];
        });
      }
    }, params: map);
  }

//选择图片方���
  Future getImage(type) async {
    FocusScope.of(context).requestFocus(FocusNode());
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return new SimpleDialog(
            title: new Text('选择'),
            children: <Widget>[
              new SimpleDialogOption(
                child: new Text('相机'),
                onPressed: () {
                  Navigator.pop(context);
                  getimgs(0, type);
                },
              ),
              new SimpleDialogOption(
                child: new Text('相册'),
                onPressed: () {
                  Navigator.pop(context);
                  getimgs(1, type);
                },
              )
            ],
          );
        });
    // var image = await ImagePicker.pickImage(source: ImageSource.gallery);
    // //_upLoadImage(image);//上传图片
    // setState(() {
    //   _image = image;
    // });
  }

  Widget build(BuildContext context) {
    return new Scaffold(
      backgroundColor: Colours.base_page_color,
      appBar: new AppBar(
        titleSpacing: 0,
        title: new Text(
          '注册检测师',
          style: TextStyle(fontSize: Config.title_size),
        ),
        backgroundColor: Colors.white,
        elevation: 0,
        // backgroundColor: Color.fromRGBO(255, 204, 48, 1),
      ),
      body: new Center(
          child: Container(
        decoration: new BoxDecoration(
          color: Colours.base_page_color,
        ),
        child: Padding(
            padding: new EdgeInsets.fromLTRB(0, 15, 0, 0),
            child: new ListView(
              children: <Widget>[buildcontent()],
            )),
      )),
    );
  }
}
